package cn.chair.dao;

import cn.chair.entity.Chair;
import cn.chair.model.admin.ChairListResp;
import life.innovation.dao.EntityDaoImpl;
import life.innovation.exception.DataReadException;
import life.innovation.model.PageList;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class ChairDao extends EntityDaoImpl<Chair> {

    public ChairDao(DataSource dataSource) {
        super(dataSource, Chair.class);
    }

    public List<ChairListResp.ChairList> getQrcodeList(Integer merchantId, String merchantName,
                                                           String chairCode, String chairName,
                                                           List<Integer> storeId) throws DataReadException {
        merchantName = (merchantName==null||merchantName.trim().isEmpty())?null:"%"+merchantName.trim()+"%";
        chairCode = (chairCode==null||chairCode.trim().isEmpty())?null:"%"+chairCode.trim()+"%";
        chairName = (chairName == null||chairName.trim().isEmpty())?null:"%"+chairName.trim()+"%";


        Map<String, Object> params = new HashMap<>();

            params.put("merchantId",merchantId);
            params.put("merchantName",merchantName);
            params.put("chairCode",chairCode);
            params.put("chairName", chairName);
        if(storeId!=null &&storeId.size()>0){
            params.put("store",storeId.get(0));
        }else{
            params.put("store",null);
        }
            params.put("storeId",storeId);



            return find("db/sql/merchant/getChairList.sql", ChairListResp.ChairList.class, params);

    }
}
